<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>

  <div id="app">
    <div>
      {{info.name}}-----{{info.age}}岁
    </div>
    <button @click="count+=1">+</button>
    <button @click="info.age+=1">年龄+1</button>
  </div>
  <script src="./js/vue.js"></script>
  <script>
    const app =new Vue({
      el:'#app',
      data:function(){
        return {
          count:0,
          info:{
            name:'张三',
            age:18
          }
        }
      },
      // 当监听的数据发生变化时，会执行里面的handler回调函数
      // handler(新的值,旧的值)
      watch:{
        count:{
          handler(newval,oldval){
            console.log('new:'+newval,'old:'+oldval);
          }
        },
        info:{
          handler(newval){
            console.log('执行了info的watch监听器');
            console.log(newval);
          },
          // 深度监听
          deep:true,
          // 立即执行一次
          immediate:true
        }
      }
    })
  </script>
</body>
</html>